#include<iostream>
#include<stack>
using namespace std;

string decode(const string& msg) {
	if (msg.size() < 2) return msg;
	stack<string> stack_;
	int index = 0;
	for (int i = 0; i < msg.size(); ++i) {
		switch (msg[i]) {
		case '[':
		case '|':
			if (index != i)
				stack_.push(msg.substr(index, i - index));
			if(msg[i]=='|')
				stack_.push(msg.substr(i, 1));
			index = i + 1;
			break;
		case ']':
		{
			string str = msg.substr(index, i - index);
			while (!stack_.empty() && stack_.top() != "|") {
				str = stack_.top() + str;
				stack_.pop();
			}
			if (!stack_.empty())
				stack_.pop();
			int num = atoi(stack_.top().c_str());
			stack_.pop();
			string tmp = "";
			while (num-- > 0) {
				tmp += str ;
			}
			stack_.push(tmp);
			index = i + 1;
		}
			break;
		default:
			break;
		}
	}
	if(index< msg.size())
		stack_.push(msg.substr(index));
	string res = "";
	while (!stack_.empty()) {
		res = stack_.top() + res;
		stack_.pop();
	}
	return res;
}

//int main() {
//	string msg;
//	cin >> msg;
//	cout << decode(msg) << endl;
//}